<html>
    <head>
        <link rel="stylesheet" href="/Public/Admin/css/personal.css"/>
        <link href="/Public/Admin/css/form.css" rel="stylesheet" />

        <link rel="stylesheet" type="text/css" href="/Public/Admin/common/layui/css/layui.css" media="all"/>
        <link rel="stylesheet" type="text/css" href="/Public/Admin/common/bootstrap/css/bootstrap.css" media="all"/>
        <link rel="stylesheet" type="text/css" href="/Public/Admin/common/global.css" />
        <link rel="stylesheet" type="text/css" href="/Public/Admin/css/adminstyle.css" />
        <link rel="stylesheet" type="text/css" href="/Public/Admin/css/style.css" />

        <script type="text/javascript" src="/Public/Admin/js/jquery.min.js"></script>
        <script type="text/javascript" src="/Public/static/layer/layer.js" ></script>
        <script type="text/javascript" src="/Public/Admin/common/layui/layui.js"></script>
        <script type="text/javascript" src="/Public/Admin/js/larry.js"></script>
        <script type="text/javascript" src="/Public/Admin/js/index.js"></script>

        <!--自定义 js-->
        <script type="text/javascript" src="/Public/static/js/formcheck.js" ></script>  
        <script type="text/javascript" src="/Public/Admin/js/common.js"></script>
        <style>
            .form-cont{padding-bottom:20px}
            .form table{border-collapse: collapse}
            .feedback{margin:20px 0}
            .feedback,.uploadFile{text-align: left;font-size:14px;margin-left:10px}
            .form .table_bg tr td{padding:5px}
            .form .table_bg tr td{font-size:14px}
            .form .table_bg tr .text_td{width:18%}
            .form .table_bg tr .text_value{width:80%}
            .feedback .f_div{border-bottom:1px solid #999;margin:0.5em 0;}
            .feedback .f_div .f_tit{font-weight:bold}
            .feedback .f_div .f_con{color:#666}
            .feedback table{width:90%;border:1px solid #999;border-collapse: collapse;margin:20px auto}
            .feedback table tr td{border:1px solid #ddd;padding:0.3em 1em}
            .feedback table tr td .lists{margin-bottom:20px}
        </style>
    </head>
    <body>
        <section class="layui-larry-box">
            <div class="larry-personal">
                <div class="layui-tab">
                    <div class="cont">
                        <div class="form-cont form">
                            {$form.print_model}
                        </div>
                        <notempty name="uploads">
                            <div class="uploadFile">
                                <h2>公共附件</h2>
                                <foreach name="uploads" item="row" key="key">
                                    <span style="display:block;padding:0.5em 0 0.3em 0">
                                        <a href="{$row.url}" download="{$row.name}">{$key+1}. {$row.name}</a>
                                        <!--<img src="/Public/Index/img/close.png" class="pointer delfile" data-fileurl="{$row.upload}"/>-->
                                    </span>
                                </foreach>
                            </div>
                        </notempty>
                        <!--会签与点评-->
                        <div class="feedback">
                            <h3>会签与点评</h3>
                            <foreach name="feeds" item="feed">
                                <div class="f_div">
                                    <div class="f_tit">第{$feed.prcs_id}步【会签】 {$feed.prcs_name} {$feed.user_id|getChinesename}</div>
                                    <div class="f_con">{$feed.content} {$feed.edit_time}</div>
                                </div>
                            </foreach>
                        </div>

                        <!--流程图-->
                        <div class="feedback">
                            <h3>流程图</h3>
                            <table>
                                <foreach name="process" item="row">
                                    <notempty name="row.data">
                                        <tr>
                                            <td>第<b><font color="red">{$row.id}</font></b>步</td>
                                            <td>序号{$row.prcs_id}：{$row.prcs_name}</td>
                                            <td>
                                        <foreach name="row.data" item="row1">
                                            <div class="lists">
                                                <div>
                                                    <if condition="$row1[prcs_flag] eq 4">
                                                        <img src="/Public/Index/img/down.png">
                                                        <elseif condition="$row1[prcs_flag] eq 1"/>
                                                        <img src="/Public/Index/img/email-close.png">
                                                        <else/>
                                                        <img src="/Public/Index/img/email-open.png">
                                                    </if>
                                                    <font color="red">{$row1.user_id|getChineseName} {$row1['op_flag'] ? '主办' : '经办'}</font>
                                                    <font color="green">[{$row1.prcs_flag|getFlagname} 
                                                    <if condition="$row1['dec'] neq null">
                                                        &nbsp;用时：<if condition="$row1['dec']['day'] neq 0">{$row1['dec']['day']}天</if><if condition="$row1['dec']['hour'] neq 0">{$row1['dec']['hour']}小时</if><if condition="$row1['dec']['min'] neq 0">{$row1['dec']['min']}分</if>{$row1['dec']['sec']}秒
                                                    </if>
                                                    ]</font>
                                                </div>
                                                <div>开始于：{$row1.prcs_time}</div>
                                                <div>结束于：{$row1.deliver_time}</div>
                                            </div>
                                        </foreach>
                                        </td>
                                        </tr>
                                    </notempty>
                                </foreach>

                            </table>
                        </div>

                        <input type="hidden" name="FORM_ID" value="{$form_id}">
                        <input type="hidden" name="RUN_ID" value="{$run_id}">
                        <input type="hidden" name="PRCS_ID" value="{$prcs}">
                        <input type="hidden" name="FLOW_ID" value="{$info.flow_id|default=0}">
                        <div class="button">
                        </div>
                    </div>
                    <input type="hidden" id="url" value="{:U('getRunData',array('run_id'=>$run_id,'flow_id'=>$flow_id))}">
                    <input type="hidden" id="feedbackUrl" value="{:U('getRunData',array('type'=>'feedback','run_id'=>$run_id))}">
                </div>
            </div>

        </section>
        <input type="hidden" id="name" value="{$download}">
    </body>
</html>
<script type="text/javascript">

    $(function () {
        $('.form table .text_value span').text('');

        $('.downPage').click();
    })

    //格式化时间
    function p(s) {
        return s < 10 ? '0' + s : s;
    }
    function getNow() {
        var date = new Date();
        return  date.getFullYear() + '-' + p(date.getMonth() + 1) + '-' + p(date.getDate()) + ' ' + p(date.getHours()) + ':' + p(date.getMinutes()) + ':' + p(date.getSeconds());
    }

    $(function () {
        $('.form input').val('').css('width', '80%');
        $('.form .table_bg .text_value span,font:last').text('');
        if ($('.title').text() == '销售合同评审表' || $('.title').text() == '采购合同评审表') {
            $('.form .table_bg .text_value font').text('');
        }

        //新建表单页面自动加载当前用户姓名、部门、日历等
        $('.form .table_bg .text_td input,.text_value input').each(function () {
            var key = $(this).attr('title');
            var id = $(this).attr('name');
            if (key.indexOf('时间') != -1 || key.indexOf('日期') != -1) {
                if (key.indexOf('申请时间') != -1 || key.indexOf('申请日期') != -1) {
                    $(this).val(getNow());
                } else {
                    $(this).addClass('dateTime');
                    $(this).attr('id', id);  //移动端日期插件需要用到id
                }
            }
            if (key.indexOf('申请人') != -1 || key.indexOf('经办人') != -1) {
                $(this).val($('#username').val());
            }
            if (key.indexOf('部门') != -1) {
                $(this).val($('#deparment').val());
            }

        })


        if ($('input[name=FLOW_ID]').val() != 0) {
            var reg = /\{(.*?)\}/g;
            var url = $('#url').val();
            var index = layer.load(3, {shade: false});
            $.ajax({
                url: url,
                async: false,
                success: function (res) {
                    console.log(res)
                    var n = 0;
                    $('.form .table_bg input,select,textarea').each(function () {
                        //9.27升级后修改
                        if (res.form[n] != 'undefined') {
                            $(this).after('<span>' + res.form[n] + '</span>');
                            $('.feedback span').text('');
                        }
                        $(this).not('.feedback textarea').remove();
                        n++;
                    })
                    //会签意见 
                    if (res.feed[n] != 'undefined') {
                        var html = '';
                        for (var i = 0; i < res.feed.length; i++) {
                            html += '<p>第' + res.feed[i].prcs_id + '步：' + res.feed[i].prcs_name + '&nbsp;&nbsp;' + res.feed[i].user_name + '<br/>' + res.feed[i].content + '&nbsp;&nbsp;' + res.feed[i].edit_time + '</p>';
                        }
                        $('.form .table_bg .text_td').each(function () {
                            if ($(this).text() == '会签意见') {
                                $(this).next().html(html);
                            }
                        })
                    }
                    layer.close(index);
                    var test = $('html').html();
                    var name = $('#name').val();
                    export_raw(name, test);
                    CloseWebPage();
                }
            })
        }
    })

    function fake_click(obj) {
        var ev = document.createEvent("MouseEvents");
        ev.initMouseEvent(
                "click", true, false, window, 0, 0, 0, 0, 0
                , false, false, false, false, 0, null
                );
        obj.dispatchEvent(ev);
    }

    function export_raw(name, data) {
        var urlObject = window.URL || window.webkitURL || window;

        var export_blob = new Blob([data]);

        var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
        save_link.href = urlObject.createObjectURL(export_blob);
        save_link.download = name;
        fake_click(save_link);
    }
    
    function CloseWebPage() {
        if (navigator.userAgent.indexOf("MSIE") > 0) {
            if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
                window.opener = null;
                window.close();
            } else {
                window.open('', '_top');
                window.top.close();
            }
        } else if (navigator.userAgent.indexOf("Firefox") > 0) {
            window.location.href = 'about:blank ';
        } else {
            window.opener = null;
            window.open('', '_self', '');
            window.close();
        }
    }


</script>

